package com.ruoyi.interceptor;


import com.ruoyi.domain.common.UserHolder;
import com.ruoyi.exception.BaseException;
import com.ruoyi.exception.TokenExpiredException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: lsx
 * @Description:  对需要登录才能访问的接口进行拦截
 * @Create:  2025/1/7 9:51
 **/
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Integer userId = UserHolder.getUserId();
        if(userId == null){
            throw new TokenExpiredException("登录状态失效，请重新登录");
        }
        return true;
    }
}